package bavaria.hightec.banking;

import java.util.Date;

import bavaria.hightec.conditions.DepositAccountConditions;
import bavaria.hightec.conditions.Conditions.runtime;
import bavaria.hightec.exceptions.OverCheckException;

public class DepositAccount extends Account {
	private double credit;
	private DepositAccountConditions conditions;
	
	public DepositAccount(Date creationDate,DepositAccountConditions conditions,int accountNumber,String accountHolder){
		super(creationDate,accountNumber,accountHolder);
		this.credit=conditions.getCreditInterest();//in prozent
		this.conditions=conditions;
		conditions.getRuntime();
	}
	
	public int getdays(runtime runtime){
		int r = 0;
		if(runtime==runtime.THREE)
			r=90;
		else if(runtime==runtime.SIX)
			r=180;
		else if(runtime==runtime.TWELVE)
			r=360;
		return r;
	}
	
	public void chargeInterest() throws OverCheckException{
		if(getCreationDate().getTime()/86400000 + getdays(conditions.getRuntime()) == BankImpl.c2.getTimeInMillis()/86400000){
			System.out.println("Festgeldkonto " + getAccountNumber() + " verzinst am: " + BankImpl.c2.getTime());
			long kontostand = getBalance();
			kontostand=(long) (kontostand*(credit/100));
			Money money= new Money(kontostand,getCurrency());
			creditEntry(money, "Zinsen");
		}
	}
	
	public void debitEntry(Money amount,String matter) throws OverCheckException{
		if(amount.getAmount()>getBalance()){
			throw new OverCheckException("Festgeldkonto nicht ueberziehbar");}
		else
		super.debitEntry(amount, matter);
		
		
		}

	
	public String toString(){
		String string ="Kontoart: Festgeld "+ super.toString() + " Habzins: " + credit;
		return string;
	}
	
	

}
